import React, { Component } from 'react';
import './index.css'

export default class Footer extends Component {
  //清除已完成任务
  handleClear = () => {
    this.props.clearAllDone()
  }
  //全选
  handleCheckAll = (event) => {
    this.props.checkAllTodo(event.target.checked)
  }
  render() {
    const { todos } = this.props
    //已完成数
    const doneCount = todos.reduce((pre, current) => {
      return current.done === true ? ++pre : pre
    }, 0)
    return (
      <div className="todo-footer">
        <label>
          <input type="checkbox" checked={doneCount === todos.length && todos.length !== 0 ? true : false} onChange={this.handleCheckAll} />
        </label>
        <span>
          <span>已完成{doneCount}</span> / 全部{todos.length}
        </span>
        <button className="btn btn-danger" onClick={this.handleClear}>清除已完成任务</button>
      </div>
    );
  }
}
